home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
301-325
/
disk_313
/
uucp
/
uucp1.lzh
/
src
/
lib
/
config.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-10
|
2KB
|
80 lines
/*
* CONFIG.C
*
* (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
*
* Extract fields from UULIB:Config
*/
#include <stdio.h>
#include <stdlib.h>
#include <config.h>
#define CTLZ ('z'&0x1F)
static char *ConfBuf = NULL;
char *
FindConfig(field)
char *field;
{
char *str;
short flen = strlen(field);
if (ConfBuf == NULL) {
FILE *fi = fopen("UULIB:Config", "r");
if (fi) {
long buflen;
fseek(fi, 0L, 2);
buflen = ftell(fi);
fseek(fi, 0L, 0);
if (buflen > 0 && (ConfBuf = malloc(buflen + 1))) {
fread(ConfBuf, buflen, 1, fi);
ConfBuf[buflen] = CTLZ; /* can't use \0 */
for (str = ConfBuf; *str; ++str) {
char *bup;
if (*str == '\n') { /* make separate strs */
*str = 0;
/* remove white space at end */
for (bup = str - 1; bup >= ConfBuf && (*bup == ' ' || *bup == 9); --bup)
*bup = 0;
}
}
} else {
ConfBuf = NULL;
}
}
}
if (ConfBuf == NULL)
return(NULL);
/*
* Search ConfBuf for Field<space/tab>
*/
for (str = ConfBuf; *str != CTLZ; str += strlen(str) + 1) {
if (*str == 0)
continue;
if (strncmp(str, field, flen) == 0 && (str[flen] == ' ' || str[flen] == '\t')) {
str += flen;
while (*str == ' ' || *str == 9)
++str;
return(str);
}
}
return(NULL);
}
char *
GetConfig(field, def)
char *field;
char *def;
{
char *result = FindConfig(field);
if (result == NULL)
result = def;
return(result);
}